package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShEquipmentStatusDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShEquipmentStatusService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShEquipmentStatus;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;


/**
 * 
* @ClassName: ShEquipmentStatusServiceImpl
* @Description: 设备状态Service实现类
* @author cyj
* @date 2015年10月7日 下午2:48:14
*
 */
@Service("shEquipmentStatusService")
public class ShEquipmentStatusServiceImpl extends BaseServiceImpl<ShEquipmentStatus, Long>implements ShEquipmentStatusService {

	@Resource
	private ShEquipmentStatusDao shEquipmentStatusDao;
	
	
	@Override
	public BaseDao<ShEquipmentStatus, Long> getDao() {
		return shEquipmentStatusDao;
	}
	
	@Override
	public DataGrid queryShEquipmentStatus(ShEquipmentStatus shEquipmentStatus, PageHelper page) {
		DataGrid grid = new DataGrid();

		if (!StringUtils.isBlank(page.getOrder())) {
			shEquipmentStatus.setOrderFieldType(page.getOrder());
		}
		if (!StringUtils.isBlank(page.getSort())) {
			shEquipmentStatus.setOrderField(page.getSort());
		}

		int startIndex = (page.getPage() - 1) * page.getRows();
		int endIndex = page.getPage() * page.getRows();
		Long count = shEquipmentStatusDao.queryShEquipmentStatuCount(shEquipmentStatus);
		grid.setTotal(count);

		if (grid.getTotal() > 0 && grid.getTotal() > startIndex) {
			shEquipmentStatus.setStartIndex(startIndex);
			shEquipmentStatus.setEndIndex(endIndex);
			List<ShEquipmentStatus> rows = shEquipmentStatusDao.queryShEquipmentStatuList(shEquipmentStatus);
			grid.setRows(rows);
		}

		return grid;
	}

	




	

}
